package com.jungle.design.mode.strategypattern.service.impl;

import com.jungle.design.mode.strategypattern.entity.enums.PayEnum;
import com.jungle.design.mode.strategypattern.entity.vo.PayReqVO;
import com.jungle.design.mode.strategypattern.service.PayService;
import com.jungle.design.mode.strategypattern.strategy.factory.PayStrategyFactory;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @author Jungle
 * @create 2024-09-15 21:47
 */
@Service
public class PayServiceImpl implements PayService {
    // @Resource
    // private AliPayStrategy aliPay;
    // @Resource
    // private UnionPayStrategy unionPay;
    // @Resource
    // private WechatPayStrategy wechatPay;
    //
    @Resource
    private PayStrategyFactory factory;



    @Override
    public void toPay(PayReqVO payReqVO) {
        Integer payType = payReqVO.getPayType();
        BigDecimal money = payReqVO.getPayAmount();
        factory.getPayStrategy(PayEnum.fromPayType(payType)).pay(money);
        // switch (payType) {
        //     case 1 -> aliPay.pay(money);
        //     case 2 ->unionPay.pay(money);
        //     case 3 ->wechatPay.pay(money);
        //     default -> throw new RuntimeException("不存在");
        // }
    }
}
